<?php

Loader::loadClass('InnoUtil', "modules/IShopStore/pnincludes");

function IShopStore_pntables()
{
    // Initialise table array
    $pntable = array();

    $categories        = createCategoriesTable();
    $subcategories     = createSubcategoriesTable();
    $item              = createItemTable();
    $images            = createImagesTable();
    $order             = createOrderTable();
    $shipment          = createShipmentTable();
    $payment           = createPaymentTable();
    $inform            = createInformTable();
    $about             = createAboutTable();
    $contactus         = createContactusTable();
    $shop_information  = createShopInformation();
    
    $pntable = array_merge($categories, $subcategories, $item, $images, $order, $shipment, $payment, $inform, $about, $contactus, $shop_information);
    
    unset($categories);
    unset($subcategories);
    unset($item);
    unset($images);
    unset($order);
    unset($shipment);
    unset($payment);
    unset($inform);
    unset($about);
    unset($contactus);
    unset($shop_information);
        
    return $pntable;
}


function &createCategoriesTable()
{
    ////////////////////////////////////////////
    //table definition categories
    ////////////////////////////////////////////
    $pntable['ishopstore_categories'] = DBUtil::getLimitedTablename('ishopstore_categories');
    $pntable['ishopstore_categories_column'] = array(
                                        'id'                => 'ctg_id',
                                        'name'              => 'ctg_name',
                                        'prefix'            => 'ctg_prefix'
    );
    $pntable['ishopstore_categories_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'TEXT',
                                        'prefix'            => 'VARCHAR(5)'
    );
    $pntable['ishopstore_categories_primary_key_column'] = 'id';

    return $pntable;
}

function &createSubcategoriesTable()
{
    ////////////////////////////////////////////
    //table definition subcategories
    ////////////////////////////////////////////
    $pntable['ishopstore_subcategories'] = DBUtil::getLimitedTablename('ishopstore_subcategories');
    $pntable['ishopstore_subcategories_column'] = array(
                                        'id'                => 'sct_id',
                                        'categories_id'     => 'sct_categories_id',
                                        'name'              => 'sct_name'
    );
    $pntable['ishopstore_subcategories_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'categories_id'     => 'INT(11) NOTNULL',
                                        'name'              => 'TEXT'
    );
    $pntable['ishopstore_subcategories_primary_key_column'] = 'id';

    return $pntable;
}

function &createItemTable()
{
    ////////////////////////////////////////////
    //table definition Item
    ////////////////////////////////////////////
    $pntable['ishopstore_item'] = DBUtil::getLimitedTablename('ishopstore_item');
    $pntable['ishopstore_item_column'] = array(
                                        'id'                => 'itm_id',
                                        'item_ref_id'       => 'itm_item_ref_id',
                                        'categories_id'     => 'itm_categories_id',
                                        'title'             => 'itm_title',
                                        'detail'            => 'itm_detail',
                                        'price'             => 'itm_price',
                                        'sale_price'        => 'itm_sale_price',
                                        'amount'            => 'itm_amount',
                                        'firstfilename'     => 'itm_firstfilename',
                                        'firstthumbname'    => 'itm_firstthumbname',
                                        'has_file'          => 'itm_has_file',
                                        'shop_status'       => 'itm_shop_status',
                                        'recommend'         => 'itm_recommend'
    );
    $pntable['ishopstore_item_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'item_ref_id'       => 'VARCHAR(255)',
                                        'categories_id'     => 'INT(11) NOTNULL',
                                        'title'             => 'TEXT',
                                        'detail'            => 'TEXT',
                                        'price'             => 'DOUBLE DEFAULT 0',
                                        'sale_price'        => 'DOUBLE DEFAULT 0',
                                        'amount'            => 'INT(50)',
                                        'firstfilename'     => 'TEXT',
                                        'firstthumbname'    => 'TEXT',
                                        'has_file'          => 'INT(11)',
                                        'shop_status'       => 'INT(11)',
                                        'recommend'         => 'INT(11)'
    );
    $pntable['ishopstore_item_primary_key_column'] = 'id';
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_item_column'], 'itm_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_item_column_def']);

    return $pntable;
}

function &createImagesTable()
{
    ////////////////////////////////////////////
    //table definition image file
    ////////////////////////////////////////////
    $pntable['ishopstore_images'] = DBUtil::getLimitedTablename('ishopstore_images');
    $pntable['ishopstore_images_column'] = array(
                                        'id'                => 'img_id',
                                        'user_id'           => 'img_user_id',
                                        'path'              => 'img_path',
                                        'item_ref_id'       => 'img_item_ref_id',
                                        'imagename'         => 'img_imagename',
                                        'thumbname'         => 'img_thumbname',
                                        'status'            => 'img_status'
    );
    $pntable['ishopstore_images_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'user_id'           => 'INT(11) NOTNULL ',
                                        'path'              => 'TEXT',
                                        'item_ref_id'       => 'VARCHAR(255) ',
                                        'imagename'         => 'TEXT',
                                        'thumbname'         => 'TEXT',
                                        'status'            => 'INT(2) DEFAULT 0'
    );
    $pntable['ishopstore_image_primary_key_column'] = 'id';

    return $pntable;
}

function &createOrderTable()
{
    ////////////////////////////////////////////
    //table definition order table
    ////////////////////////////////////////////
    $pntable['ishopstore_order'] = DBUtil::getLimitedTablename('ishopstore_order');
    $pntable['ishopstore_order_column'] = array(
                                        'id'               => 'order_id',
                                        'orderer'          => 'order_orderer',
                                        'phone_number'     => 'order_phone_number',
                                        'email'            => 'order_email',
                                        'house_no'         => 'order_house_no',
                                        'moo'              => 'order_moo',
                                        'soi'              => 'order_soi',
                                        'road'             => 'order_road',
                                        'village'          => 'order_village',
                                        'tambon'           => 'order_tambon',
                                        'district'         => 'order_district',
                                        'province'         => 'order_province',
                                        'zipcode'          => 'order_zipcode',
                                        'status'           => 'order_status',
                                        'shipment_id'      => 'order_shipment_id'

    );
    $pntable['ishopstore_order_column_def'] = array(
                                        'id'               => 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY',
                                        'orderer'          => 'VARCHAR(255)',
                                        'phone_number'     => 'VARCHAR(15)',
                                        'email'            => 'VARCHAR(255)',
                                        'house_no'         => 'VARCHAR(10)',
                                        'moo'              => 'VARCHAR(10)',
                                        'soi'              => 'VARCHAR(10)',
                                        'road'             => 'VARCHAR(255)',
                                        'village'          => 'VARCHAR(255)',
                                        'tambon'           => 'VARCHAR(255)',
                                        'district'         => 'VARCHAR(255)',
                                        'province'         => 'VARCHAR(255)',
                                        'zipcode'          => 'VARCHAR(5)',
                                        'status'           => 'VARCHAR(5) DEFAULT 1 ',
                                        'shipment_id'      => 'INT(11)'

    );
    $pntable['ishopstore_order_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_order_column'], 'order_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_order_column_def']);
    
    ////////////////////////////////////////////
    //table definition order_item table
    //this table related with item table and order table
    ////////////////////////////////////////////
    $pntable['ishopstore_order_item'] = DBUtil::getLimitedTablename('ishopstore_order_item');
    $pntable['ishopstore_order_item_column'] = array(
                                        'id'               => 'orditm_id',
                                        'item_id'          => 'orditm_item_id',
                                        'order_id'         => 'orditm_order_id',
                                        'quantity'         => 'orditm_quantity'
    );
    $pntable['ishopstore_order_item_column_def'] = array(
                                        'id'               => 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY',
                                        'item_id'          => 'INT(11) NOT NULL',
                                        'order_id'         => 'INT(11) NOT NULL',
                                        'quantity'         => 'INT(11) NOT NULL'
    );
    $pntable['ishopstore_order_item_primary_key_column'] = 'id';
    
    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_order_item_column'], 'orditm_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_order_item_column_def']);

    return $pntable;
}

function &createShipmentTable()
{
    ////////////////////////////////////////////
    //table definition Shipment
    ////////////////////////////////////////////
    $pntable['ishopstore_shipment'] = DBUtil::getLimitedTablename('ishopstore_shipment');
    $pntable['ishopstore_shipment_column'] = array(
                                        'id'                => 'shi_id',
                                        'shipment'          => 'shi_shipment',
                                        'price'             => 'shi_price',
                                        'detail'            => 'shi_detail'
    );
    $pntable['ishopstore_shipment_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'shipment'          => 'VARCHAR(255)',
                                        'price'             => 'DOUBLE DEFAULT 0',
                                        'detail'            => 'TEXT'
    );
    $pntable['ishopstore_shipment_primary_key_column'] = 'id';

    return $pntable;
}

function &createPaymentTable()
{
    ////////////////////////////////////////////
    //table definition Payment
    ////////////////////////////////////////////
    $pntable['ishopstore_payment'] = DBUtil::getLimitedTablename('ishopstore_payment');
    $pntable['ishopstore_payment_column'] = array(
                                        'id'                          => 'pay_id',
                                        'payment'                     => 'pay_payment',
                                        'payment_bank_name'           => 'pay_payment_bank_name',
                                        'payment_bank_branch'         => 'pay_payment_bank_branch',
                                        'payment_bank_account_name'   => 'pay_payment_bank_account_name',
                                        'payment_bank_account_type'   => 'pay_payment_bank_account_type',
                                        'payment_bank_account_no'     => 'pay_payment_bank_account_no'
    );
    $pntable['ishopstore_payment_column_def'] = array(
                                        'id'                          => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'payment'                     => 'VARCHAR(255)',
                                        'payment_bank_name'           => 'VARCHAR(255)',
                                        'payment_bank_branch'         => 'VARCHAR(255)',
                                        'payment_bank_account_name'   => 'VARCHAR(255)',
                                        'payment_bank_account_type'   => 'VARCHAR(255)',
                                        'payment_bank_account_no'     => 'VARCHAR(20)'
    );
    $pntable['ishopstore_payment_primary_key_column'] = 'id';

    return $pntable;
}

function &createInformTable()
{
    ////////////////////////////////////////////
    //table definition Paid
    ////////////////////////////////////////////
    $pntable['ishopstore_inform'] = DBUtil::getLimitedTablename('ishopstore_inform');
    $pntable['ishopstore_inform_column'] = array(
                                        'id'                          => 'inf_id',
                                        'order_id'                    => 'inf_order_id',
                                        'payment_id'                  => 'inf_payment_id',
                                        'payer_name'                  => 'inf_payer_name',
                                        'pay'                         => 'inf_pay',
                                        'transfer_date'               => 'inf_transfer_date',
                                        'detail'                      => 'inf_detail',
                                        'status'                      => 'inf_status'
    );
    $pntable['ishopstore_inform_column_def'] = array(
                                        'id'                          => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'order_id'                    => 'INT(11)',
                                        'payment_id'                  => 'INT(11)',
                                        'payer_name'                  => 'VARCHAR(255)',
                                        'pay'                         => 'DOUBLE DEFAULT 0',
                                        'transfer_date'               => 'DATETIME',
                                        'detail'                      => 'TEXT',
                                        'status'                      => 'INT(5)'
    );
    $pntable['ishopstore_inform_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_inform_column'], 'inf_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_inform_column_def']);


    return $pntable;
}

function &createAboutTable()
{
    ////////////////////////////////////////////
    //table definition subcategories
    ////////////////////////////////////////////
    $pntable['ishopstore_about'] = DBUtil::getLimitedTablename('ishopstore_about');
    $pntable['ishopstore_about_column'] = array(
                                        'id'                => 'abo_id',
                                        'how_to'            => 'abo_how_to',
                                        'about_us'          => 'abo_about_us',
                                        'contact_us'        => 'abo_contact_us',
                                        'map_lat'           => 'abo_map_lat',
                                        'map_lon'           => 'abo_map_lon'
    );
    $pntable['ishopstore_about_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'how_to'            => 'TEXT',
                                        'about_us'          => 'TEXT',
                                        'contact_us'        => 'TEXT',
                                        'map_lat'           => 'TEXT',
                                        'map_lon'           => 'TEXT'
    );
    $pntable['ishopstore_about_primary_key_column'] = 'id';

    return $pntable;
}

function &createContactusTable()
{
    ////////////////////////////////////////////
    //table definition subcategories
    ////////////////////////////////////////////
    $pntable['ishopstore_contactus'] = DBUtil::getLimitedTablename('ishopstore_contactus');
    $pntable['ishopstore_contactus_column'] = array(
                                        'id'                => 'con_id',
                                        'name'              => 'con_name',
                                        'email'             => 'con_email',
                                        'phone'             => 'con_phone',
                                        'headline'          => 'con_headline',
                                        'message'           => 'con_message'
    );
    $pntable['ishopstore_contactus_column_def'] = array(
                                        'id'                => 'INT(11) NOTNULL AUTOINCREMENT PRIMARY',
                                        'name'              => 'VARCHAR(50)',
                                        'email'             => 'VARCHAR(50)',
                                        'phone'             => 'VARCHAR(50)',
                                        'headline'          => 'VARCHAR(255)',
                                        'message'           => 'TEXT'
    );
    $pntable['ishopstore_contactus_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_contactus_column'], 'con_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_contactus_column_def']);

    return $pntable;
}


function &createShopInformation(){

    ////////////////////////////////////////////
    //table information 
    ////////////////////////////////////////////
    $pntable['ishopstore_information'] = DBUtil::getLimitedTablename('ishopstore_information');
    $pntable['ishopstore_information_column'] = array(
                                        'uid'               => 'info_uid',
                                        'firstname'         => 'info_firstname',
                                        'lastname'          => 'info_lastname',
                                        'mobilephone'       => 'info_mobilephone',
                                        'gender'            => 'info_gender',
                                        'house_no'          => 'info_house_no',                                        
                                        'moo'               => 'info_moo',                                           
                                        'soi'               => 'info_soi',                                         
                                        'road'              => 'info_road',                                         
                                        'village'           => 'info_village', 
                                        'tambon'            => 'info_tambon', 
                                        'district'          => 'info_district',                                                                                                                         
                                        'province'          => 'info_province', 
                                        'zipcode'           => 'info_zipcode',                                                                                 
                                        'shop_subdomain'    => 'info_shop_subdomain',
                                        'shop_domain'       => 'info_shop_domain',
                                        'shop_name'         => 'info_shop_name',
                                        'shop_database'     => 'info_shop_database',
                                        'shop_description'  => 'info_shop_description',                                                                                
                                        'shop_icon'         => 'info_shop_icon',                                                                                
                                        'shop_theme'        => 'info_shop_theme'                                                                                                                                                                                                                                                                                               
    );
    $pntable['ishopstore_information_column_def'] = array(
                                        'uid'               => 'INT(11) NOTNULL PRIMARY',
                                        'firstname'         => 'VARCHAR(255)',
                                        'lastname'          => 'VARCHAR(255)',
                                        'mobilephone'       => 'VARCHAR(50)',
                                        'gender'            => 'INT(1) DEFAULT 1',
                                        'house_no'          => 'VARCHAR(50)',                                        
                                        'moo'               => 'VARCHAR(50)',                                           
                                        'soi'               => 'VARCHAR(50)',                                         
                                        'road'              => 'VARCHAR(50)',                                         
                                        'village'           => 'VARCHAR(255)', 
                                        'tambon'            => 'VARCHAR(255)', 
                                        'district'          => 'VARCHAR(255)',                                                                                                                         
                                        'province'          => 'VARCHAR(255)', 
                                        'zipcode'           => 'INT(5)',                                                                                 
                                        'shop_subdomain'    => 'VARCHAR(255)',
                                        'shop_domain'       => 'VARCHAR(255)',
                                        'shop_name'         => 'VARCHAR(255)',
                                        'shop_database'     => 'VARCHAR(255)',
                                        'shop_description'  => 'TEXT',                                        
                                        'shop_icon'         => 'TEXT',                                        
                                        'shop_theme'        => 'VARCHAR(255)'                                             
    );                                        
    $pntable['ishopstore_information_primary_key_column'] = 'id';

    // add standard data fields
    ObjectUtil::addStandardFieldsToTableDefinition ($pntable['ishopstore_information_column'], 'information_');
    ObjectUtil::addStandardFieldsToTableDataDefinition($pntable['ishopstore_information_column_def']);

    return $pntable;

}

?>